﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MensUnoShop.Models;
using MensUnoShop.Models.ViewModels;
using System.Xml.Linq;


namespace MensUnoShop.Controllers
{
    public class NewsController : Controller
    {
        //
        // GET: /News/
        private Member _member;
        private List<Tag> _toptaglist,_navlist,_leftlist;
        private string _title;
        private NewsViewModel _iv;
        private List<UNews> _newslist;
        private XElement _hotkeylist;

        public NewsController()
        {
            _member = MemberFactory.GetMember();
            _toptaglist = TagFactory.GetTopTagList();
            _leftlist = TagFactory.GetLeftTagList(1);
            _hotkeylist = KeyWordFactory.GetHotKeyList();

        }

        public ActionResult Index(int nid)
        {
            try
            {
                _newslist = NewsFactory.GetNewsList();
                UNews n = _newslist.SingleOrDefault(nn=>nn.Nid==nid);
                if (n != null)
                {
                    _newslist.Remove(n);
                    _iv = new NewsViewModel { MEMBER = _member, TITLE = _title, TOPLIST = _toptaglist, LEFTTAG = _leftlist, NEWSLIST = _newslist, NEWS = n, HOTKEYLIST = _hotkeylist };
                    return View(_iv);
                }
                else
                    return Redirect("/");
            }
            catch { return Redirect("/"); }
        }

        public ActionResult news1()
        {
            return View(_iv);
        }

        public ActionResult news2()
        {
            return View(_iv);
        }

        public ActionResult news3()
        {
            return View(_iv);
        }


    }
}
